package com.aabte.spring.validator;

import javax.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author Daniel
 * @version 1.0
 * @date 2020/4/25
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class RspDTO<T> {

  @NotNull
  private String code;
  private String message;
  private T data;

  public RspDTO(@NotNull String code, String message) {
    this.code = code;
    this.message = message;
  }

  public static <T> RspDTO<T> success() {
    return RspDTO.<T>builder().code(Constant.OK).message("OK").build();
  }

  public static <T> RspDTO<T> paramFail(String message) {
    return RspDTO.<T>builder().code(Constant.PARAM_FAIL_CODE).message(message).build();
  }

  public static <T> RspDTO<T> success(T data) {
    return RspDTO.<T>builder().code(Constant.OK).message("OK").data(data).build();
  }

  public static <T> RspDTO<T> nonAbsent(String message) {
    return RspDTO.<T>builder().code(Constant.NOT_FOUND).message(message).build();
  }
}
